package cn.stylefeng.guns.sys.core.util;

import cn.stylefeng.guns.sys.modular.system.model.result.BtyCwHuopeiResult;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyMdYydzResult;
import cn.stylefeng.guns.sys.modular.system.model.result.ProjectResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

public class PageUtil {
    /**
     * @param page  页数
     * @param limit 每页几条数据
     * @param list  分页数据
     * @return
     */
    public static List<ProjectResult> list(int page, int limit, List<ProjectResult> list) {
        int size = list.size();
        int pageCount = size / limit;
        int fromIndex = limit * (page - 1);
        int toIndex = fromIndex + limit;
        if (toIndex >= size) {
            toIndex = size;
        }
        if (page > pageCount + 1) {
            fromIndex = 0;
            toIndex = 0;
        }
        return list.subList(fromIndex, toIndex);
    }

    public static List<BtyCwHuopeiResult> listPage(int page, int limit, List<BtyCwHuopeiResult> list) {
        int size = list.size();
        int pageCount = size / limit;
        int fromIndex = limit * (page - 1);
        int toIndex = fromIndex + limit;
        if (toIndex >= size) {
            toIndex = size;
        }
        if (page > pageCount + 1) {
            fromIndex = 0;
            toIndex = 0;
        }
        return list.subList(fromIndex, toIndex);
    }

    public static List<BtyMdYydzResult> yydzPage(int page, int limit, List<BtyMdYydzResult> list) {
        int size = list.size();
        int pageCount = size / limit;
        int fromIndex = limit * (page - 1);
        int toIndex = fromIndex + limit;
        if (toIndex >= size) {
            toIndex = size;
        }
        if (page > pageCount + 1) {
            fromIndex = 0;
            toIndex = 0;
        }
        return list.subList(fromIndex, toIndex);
    }

}
